package com.captainbank.tcl.tclapplication.ui.activity.function;

import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.View;

import com.captainbank.tcl.tclapplication.R;
import com.captainbank.tcl.tclapplication.ui.activity.basic.BaseActivity;
import com.captainbank.tcl.tclapplication.ui.views.LoginDialogFragment;
import com.captainbank.tcl.tclapplication.ui.views.ShowDialogFragment;
import com.captainbank.tcl.tclapplication.utils.MyToast;
import com.gyf.barlibrary.ImmersionBar;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by TCL on 2019/4/4.
 * Describe:
 */
public class DialogFragmentActivity extends BaseActivity implements LoginDialogFragment.LoginInputListener {
    @BindView(R.id.toolbar)
    Toolbar toolbar;

    private LoginDialogFragment ldf;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_dialog_fragment;
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                .fitsSystemWindows(true)
                .statusBarColor(R.color.colorPrimary)
                .statusBarDarkFont(true, 0.2f)
                .init();
    }

    @Override
    protected void initView() {
        toolbar.setTitle(getString(R.string.title_dialog_fragment));
    }

    @OnClick({R.id.btn_show1, R.id.btn_show2})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_show1:
//                if(ldf==null){
                ImmersionBar.with(this).keyboardEnable(true).init();
                    System.out.println("输出new");
                    ldf = LoginDialogFragment.newInstance("登录");
//                }
                System.out.println("输出show");
                ldf.show(getSupportFragmentManager(),"loginDialogFragment");
                break;
            case R.id.btn_show2:
                ShowDialogFragment sdf  = new ShowDialogFragment();
                sdf.show(getSupportFragmentManager(),"showDialogFragment");
                break;
        }
    }

    @Override
    public void onLoginInputComplete(String username, String password) {
        if(username.equals(password)){
            MyToast.toastSuccess(this,"登录成功",false);
        }else{
            MyToast.toastError(this,"账号密码错误",false);
        }
    }

//    @Override
//    public boolean onKeyDown(int keyCode, KeyEvent event) {
////        if (keyCode == KeyEvent.KEYCODE_BACK && ldf != null && ldf.isVisible()) {
////            ldf.dismiss();
////            return true;
////        }
//        return super.onKeyDown(keyCode, event);
//    }
}
